package com.lee.api.fallback;

import com.lee.api.client.ReplyClient;
import com.lee.common.model.AppResult;
import com.lee.common.model.ArticleReply;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;



@Slf4j
public class ReplyClientFallback implements FallbackFactory<ReplyClient> {
    @Override
    public ReplyClient create(Throwable cause) {
        return new ReplyClient() {
            @Override
            public AppResult create(HttpServletRequest request, Long articleId, String content) {
                throw new RuntimeException(cause);
            }

            @Override
            public AppResult<List<ArticleReply>> getRepliesByArticleId(Long articleId) {
                log.error("远程调用getRepliesByArticleId方法出现异常，参数：{}",articleId, cause);
                // 查询购物车允许失败，查询失败，返回空集合
                return  AppResult.success(Collections.emptyList());
            }

            @Override
            public List<ArticleReply> selectByArticleId(Long id) {
                return null;
            }
        };
    }

}
